package xml.parserDOM;

import java.util.ArrayList;
import java.util.List;

import Clases.Tag;

public class Arbol {
	
	    private Nodo<Tag> rootElement;
	    private String docType;
	    private String docInfo;
	     
	    /**
	     * Default ctor.
	     */
	    public Arbol() {
	        super();
	    }
	 
	    /**
	     * Return the root Node of the tree.
	     * @return the root element.
	     */
	    public Nodo<Tag> getRootElement() {
	        return this.rootElement;
	    }
	 
	    /**
	     * Set the root Element for the tree.
	     * @param rootElement the root element to set.
	     */
	    public void setRootElement(Nodo<Tag> rootElement) {
	        this.rootElement = rootElement;
	    }
	     
	    /**
	     * Returns the Tree<T> as a List of Node<T> objects. The elements of the
	     * List are generated from a pre-order traversal of the tree.
	     * @return a List<Node<T>>.
	     */
	    public List<Nodo<Tag>> toList() {
	        List<Nodo<Tag>> list = new ArrayList<Nodo<Tag>>();
	        walk(rootElement, list);
	        return list;
	    }
	     
	    /**
	     * Returns a String representation of the Tree. The elements are generated
	     * from a pre-order traversal of the Tree.
	     * @return the String representation of the Tree.
	     */
	    public String toString() {
	        return toList().toString();
	    }
	     
	    /**
	     * Walks the Tree in pre-order style. This is a recursive method, and is
	     * called from the toList() method with the root element as the first
	     * argument. It appends to the second argument, which is passed by reference     * as it recurses down the tree.
	     * @param element the starting element.
	     * @param list the output of the walk.
	     */
	    private void walk(Nodo<Tag> element, List<Nodo<Tag>> list) {
	        list.add(element);
	        for (Nodo<Tag> data : element.getChildren()) {
	            walk(data, list);
	        }
	    }

		public String getDocType() {
			return docType;
		}

		public void setDocType(String docType) {
			this.docType = docType;
		}

		public String getDocInfo() {
			return docInfo;
		}

		public void setDocInfo(String docInfo) {
			this.docInfo = docInfo;
		}
	    
	    
	

}
